package com.ztk.threadbasic.threadlocal;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadLocal03 {
    ThreadLocal<String> threadLocal = new ThreadLocal<>();
    public String getContent() {
        return threadLocal.get();
    }

    public void setContent(String content) {
        threadLocal.set(content);
    }

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        ThreadLocal03 threadLocal01 = new ThreadLocal03();
        for (int i = 0; i < 500; i++) {
            int finalI = i;
            executorService.execute(() -> {
                threadLocal01.setContent(Thread.currentThread().getName() + "-" + finalI);
                System.out.println(Thread.currentThread().getName() + "->" + threadLocal01.getContent());
            });
        }
        Thread.sleep(1000000);
    }
}
